package puzzle.nurikabe.loader;

import puzzle.common.loader.AbstractLoader;
import puzzle.common.loader.Preprocessor;
import puzzle.nurikabe.data.NurikabeBoard;

public class NurikabeLoader extends AbstractLoader<NurikabeBoard> {

	public NurikabeLoader() {
		super("\\s+");
	}

	@Override
	protected NurikabeBoard process(Preprocessor pp) {
		NurikabeBoard b = new NurikabeBoard(pp.getWidth(), pp.getHeight());
		for (int y = 0; y < pp.getLines().size(); y++) {
			String[] fields = pp.getLines().get(y);
			for (int x = 0; x < pp.getWidth(); x++) {
				int n = Integer.parseInt(fields[x]);
				if (n > 0) {
					b.addShima(x, y, n);
				}
			}
		}
		return b;
	}

}
